<template>
	<!--分销中心 - 二维码 -->
	<view class="qrcode">
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">我的二维码</block>
		</cu-custom>			
		<image :src="img" @tap="preImg(img)" mode="widthFix"></image>
		<uni-fab :pattern="pattern" :content="content" :horizontal="horizontal" :vertical="vertical" :direction="direction"
		 @trigger="trigger"></uni-fab>
	</view>
</template>

<script>
	import { codePicture } from '@/common/api/lbt'
	import UniFab from '@/components/uni-fab'
	import { mapGetters } from 'vuex'
	export default {
		name: 'codePicture',
		data() {
			return {
				info: {},
				img: "",
				horizontal: 'right',
				vertical: 'bottom',
				direction: 'vertical',
				action: 0,
				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor: '#e4393c'
				},
				content: [{
					iconPath: '/static/refresh.png',
					selectedIconPath: '/static/refresh.png',
					text: '刷新',
					active: false
				}]
			}
		},
		onLoad() {
			this.getInfo()
		},
		methods: {
			preImg(e) {
				uni.previewImage({
					urls: [this.img],
					current: e
				})
			},
			trigger(e) {
				//this.content[e.index].active = !e.item.active;
				switch (e.index) {
					case 0:
						this.action = 1
						this.getInfo()
						break;
				}
			},
			getInfo() {
				uni.showLoading({ mask: true })
				codePicture({refresh: this.action, ticket: this.userInfo.ticket}).then(res => {
					uni.hideLoading()
					this.img = res.data
				})
			}
		},
		components: {
			UniFab
		},
		computed: {
			...mapGetters([
				'userInfo'
			])
		}
	}
</script>

<style lang="less">
@import '../common/styles/variables.less';
.fixedBody;
.qrcode {
	height: 100%;
	image {
		width: 100%;
	}
}
</style>
